function [xi_tt, P_tt, xi_ttm1, P_ttm1] = ...
  ecn_filter_kalman(F, Q, y_t, A, x_t, H, R, P_tm1tm1, xi_tm1tm1)

% Prediction
xi_ttm1 = F * xi_tm1tm1;
P_ttm1 = F * P_tm1tm1 * F' + Q;

% Updating
K_t = P_ttm1 * H / (H' * P_ttm1 * H + R);
xi_tt = xi_ttm1 + K_t * (y_t - A' * x_t - H' * xi_ttm1);
P_tt = P_ttm1 - K_t * H' * P_ttm1;